//
//  MBProgessHUD_BS.m
//  MyLover
//
//  Created by yeyifeng on 16/12/2.
//  Copyright © 2016年 yeyifeng. All rights reserved.
//

#import "MBProgessHUD_BS.h"

@implementation MBProgessHUD_BS


+(void)showInView:(UIView*)view andText:(NSString*)text{
    
    [MBProgressHUD hideHUDForView:view animated:YES];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.label.text = text;
}

+(void)showTextModeInView:(UIView *)view andText:(NSString *)text{
    
    [MBProgressHUD hideHUDForView:view animated:YES];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.label.text = text;
    hud.minShowTime = 1;
    [self removeHUDWithTime:1.3 andView:view];
}

+(void)showInView:(UIView *)view andHUDMode:(MBProgressHUDMode)mode andText:(NSString *)text{
   
    [MBProgressHUD hideHUDForView:view animated:YES];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = mode;
    hud.label.text = text;
    hud.minShowTime = 1;
    //非加载框 1秒自动移除
    if (mode != MBProgressHUDModeIndeterminate) {
        [self removeHUDWithTime:1 andView:view];
    }
}


//移除HUD
+(void)removeHUDWithTime:(NSTimeInterval)time andView:(UIView *)view{
    
    double delayInSeconds = time;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [MBProgressHUD hideHUDForView:view animated:YES];
    });
}

@end
